/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package cn.ac.iie.di.tools;

//import cn.ac.iie.di.gloabl.GlobalParas;
import cn.ac.iie.di.global.GlobalParas;
import java.io.IOException;
import java.util.Random;
import org.apache.http.client.fluent.Request;
import org.apache.log4j.Logger;
import static java.lang.Thread.sleep;
import java.util.logging.Level;

/**
 *
 * @author Austin
 */
public class RemoveDuplicate {
    
    static private final Logger log = Logger.getLogger(RemoveDuplicate.class.getName());
    
    public static int[] getQCId(String strs) throws IOException, InterruptedException {
//        String url = "http://10.136.64.40:7349/check/";
//        String mmm = RuntimeEnv.getParamAsString(RuntimeEnv.QuchongReds);
        String[] url = GlobalParas.RM_DUP.split("[;]");
//        String[] url = "http://localhost:9996/check/".split("[;]");
//        String[] url = mmm.split("[;]");
        //String url = "http://192.168.11.95:7348/trans/";
        String _id = null;
        while (true) {
            try {
                Random r = new Random();
//                String str = GenerateMD5.string2MD5(strs);
                _id = Request.Post(url[r.nextInt(url.length)]).bodyByteArray(strs.getBytes()).socketTimeout(1800000).connectTimeout(1800000).execute().returnContent().asString();
                //_id = Request.Post(url).bodyByteArray(str.getBytes()).execute().returnContent().asString();
                if (_id.trim().equals("") || _id == null) {
                    log.info("_id is null or kong " + _id);
                    sleep(500);
                    continue;
                } else {
                    break;
                }
            } catch (Exception E) {
                System.out.println("get https and sleep 1s" + E.toString());
                sleep(1000);
            }
        }
        String[] sss = _id.split("[\n]");
        int[] ints = new int[sss.length];
        for (int j = 0; j < sss.length; j++) {
            try {
                int tu = Integer.valueOf(sss[0].trim());
                switch (tu) {
                    case 0:
                        ints[j] = 1000;
                        break;
                    case 1:
                        ints[j] = 10000;
                        break;
                    default:
                        ints[j] = 0;
                        break;
                }
            } catch (Exception E) {
                ints[j] = 0;
            }
        }
        return ints;
    }
    
    public static void main(String[] args) {
        String i = "Hadiri International Education Expo 2017 w/ @icaneducation . Bs daftar langsung kuliah ke luar negeri. #IEE2017pic.twitter.com/1MSkSh8CqT";
        try {
            int[] l = RemoveDuplicate.getQCId(i);
            System.out.println("数组" + l[0]);
        } catch (IOException ex) {
            java.util.logging.Logger.getLogger(RemoveDuplicate.class.getName()).log(Level.SEVERE, null, ex);
        } catch (InterruptedException ex) {
            java.util.logging.Logger.getLogger(RemoveDuplicate.class.getName()).log(Level.SEVERE, null, ex);
        }
    }
}
